<?php
include_once("../includes/common.php");
include_once("../class/User.class.php");
require_once("../islogin.php");

if ($islogin!=1){
    header('Location: /login.php');
    exit;
}
if($user_info["message"]["u_type"]==3){
    header('Location: /control/check_note.php');
    exit;
}
$menuavatar = !$user_info["message"]["avatar"] ? "/data/avatar/default.jpg" : $user_info["message"]["avatar"];
$pageName = "笔记审核";

$ischecker = [];

$ischecker['statistics'] = json_decode($user->user_statistics($user_info['message']['user_id']),true)['message'];
$ischecker['reg_time'] = $user_info['message']['reg_time'];
$ischecker['note_num'] = $user->getUserNoteNum($user_info['message']['user_id']);


// 当前时间戳
$current_time = time();

// 条件计算
$reg_days = floor(($current_time - (int)$ischecker["reg_time"]) / (24 * 60 * 60));
$condition1 = $reg_days >= 365;

$fans_count = (int)$ischecker["statistics"]["fans_count"];
$condition2 = $fans_count >= 5000;

$likes_received_count = (int)$ischecker["statistics"]["likes_received_count"];
$condition3 = $likes_received_count >= 10000;

$note_num = (int)$ischecker["note_num"];
$condition4 = $note_num > 15;
// 检查是否满足所有条件
$all_conditions_met = $condition1 && $condition2 && $condition3 && $condition4;

if (isset($_GET['checker'])){
    if ($all_conditions_met){
        $res = json_decode($user->upUserChecker($user_info['message']['user_id']),true);
        if ($res['status']==201){
            echo '<script>alert("'.$res['message'].'");window.location.href="/control/checker.php";</script>';
            exit;
        }
        header('Location: /control/check_note.php?msg=success');
        exit;
    }
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <?php require_once('head.php'); ?>
</head>
<body>
    
<!--==================== Preloader Start ====================-->
  <div class="preloader">
    <div class="loader"></div>
  </div>
<!--==================== Preloader End ====================-->

<!--==================== Sidebar Overlay End ====================-->
<div class="side-overlay"></div>
<!--==================== Sidebar Overlay End ====================-->

<?php require_once('user_menu.php'); ?>
    <div class="dashboard-main-wrapper">
        <?php require_once('top_navbar.php'); ?>
        <div class="dashboard-body">
             
            <div class="card">
    <div class="card-header border-bottom">
        <h4 class="mb-4" style="display: flex;align-items: center;">
            <img src="/static/img/logo.png" style="margin-right: 10px"/>审核官
        </h4>
        <p class="text-gray-600 mt-12 text-15">符合条件，申请成功后可以审核他人的笔记哦 ~</p>
    </div>
    <div class="card-body">
        <div class="row gy-4">
            <div class="col-xxl-12">
                <div class="plan-item rounded-16 border border-gray-100 transition-2 position-relative active">
                    <span class="plan-badge py-4 px-16 bg-main-600 text-white position-absolute inset-inline-end-0 inset-block-start-0 mt-8 text-15">申请条件</span>
                    <span class="text-2xl d-flex mb-16 text-main-600"><i class="ph ph-planet"></i></span>
                    <h3 class="mb-4">审核官 申请</h3>
                    <h2 class="h1 fw-medium text-main mb-32 mt-16 pb-32 border-bottom border-gray-100 d-flex gap-4">
                        永久 <span class="text-md text-gray-600">/时限</span>
                    </h2>

                    <ul>
                        <li class="flex-align gap-8 text-gray-600 mb-lg-4 mb-20">
                            <?php if ($condition1): ?>
                                <span class="text-24 d-flex text-main-600">
                <i class="ph ph-check-circle"></i>
            </span>
                                注册时间大于1年 <strong>满足：<?= $reg_days ?>/365天</strong>
                            <?php else: ?>
                                <span class="text-24 d-flex text-danger-600">
                <i class="ph ph-x-circle"></i>
            </span>
                                注册时间大于1年 <strong>不满足：<?= $reg_days ?>/365天</strong>
                            <?php endif; ?>
                        </li>
                        <li class="flex-align gap-8 text-gray-600 mb-lg-4 mb-20">
                            <?php if ($condition2): ?>
                                <span class="text-24 d-flex text-main-600">
                <i class="ph ph-check-circle"></i>
            </span>
                                粉丝数大于等于5000粉 <strong>满足：<?= $fans_count ?>/5000粉</strong>
                            <?php else: ?>
                                <span class="text-24 d-flex text-danger-600">
                <i class="ph ph-x-circle"></i>
            </span>
                                粉丝数大于等于5000粉 <strong>不满足：<?= $fans_count ?>/5000粉</strong>
                            <?php endif; ?>
                        </li>
                        <li class="flex-align gap-8 text-gray-600 mb-lg-4 mb-20">
                            <?php if ($condition3): ?>
                                <span class="text-24 d-flex text-main-600">
                <i class="ph ph-check-circle"></i>
            </span>
                                点赞+收藏数大于等于1万 <strong>满足：<?= $likes_received_count ?>/10000 个</strong>
                            <?php else: ?>
                                <span class="text-24 d-flex text-danger-600">
                <i class="ph ph-x-circle"></i>
            </span>
                                点赞+收藏数大于等于1万 <strong>不满足：<?= $likes_received_count ?>/10000 个</strong>
                            <?php endif; ?>
                        </li>
                        <li class="flex-align gap-8 text-gray-600 mb-lg-4 mb-20">
                            <?php if ($condition4): ?>
                                <span class="text-24 d-flex text-main-600">
                <i class="ph ph-check-circle"></i>
            </span>
                                笔记数量大于15篇 <strong>满足：<?= $note_num ?>/15 篇</strong>
                            <?php else: ?>
                                <span class="text-24 d-flex text-danger-600">
                <i class="ph ph-x-circle"></i>
            </span>
                                笔记数量大于15篇 <strong>不满足：<?= $note_num ?>/15 篇</strong>
                            <?php endif; ?>
                        </li>
                    </ul>
                    <?php if ($all_conditions_met): ?>
                        <button onclick="window.location.href='<?= "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>?checker'" class="btn btn-main w-100 rounded-pill py-16 border-main-600 text-17 fw-medium mt-32">申 请 成 为 审 核 官</button>
                    <?php else: ?>
                        <button disabled="disabled" class="btn btn-main w-100 rounded-pill py-16 border-main-600 text-17 fw-medium mt-32">暂 不 满 足 条 件 无 法 申 请</button>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>
           
        </div>

        <?php require_once('footer.php'); ?>
    </div>

<?php require_once('foot.php'); ?>


    </body>
</html>